<template>
  <div class="header">
    <img src="@/assets/images/logo.png">
    <Header-search />
    <Header-cart />
    <span v-if="!user">您好，请<router-link to="/login">登录</router-link>    免费<router-link to="/register">注册</router-link></span>
    <span v-else>欢  迎  您,{{ user.username }}, <a href="javascript:;" @click="logout"> 退出登录  </a></span> 
  </div>
</template>

<script>
import HeaderSearch from './HeaderSearch.vue'
import HeaderCart from './HeaderCart.vue'
import { mapState,mapMutations } from 'vuex'
export default {
  name: 'Header',
  components:{
    HeaderSearch,
    HeaderCart,
  },
  computed:{
    ...mapState('user',[
      'user',
    ])
  },
  methods:{
    logout(){
      this.deleteUser();
    },
    ...mapMutations('user',[
      'deleteUser'
    ])
  },
}
</script>

<style scoped>

</style>
